<template>
  <div>
    <div class="all-data">
      <div class="title">实时数据</div>
      <el-row>
        <el-col :span="12">
          <div class="item item4">
            <div class="img">
              <img src="@/assets/images/warnView/device/temp.png" />
            </div>
            <div class="center"
                 v-if="temp">
              <div class="value">
                <span class="num">{{Number(temp.val)?temp.val.toFixed(1):0}}</span>
                <span class="unit">°C</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade"
                     :class="temp.evaluate.healthLevelShow | tempLevelFil">{{temp.evaluate.healthLevelShow}}</div>
              </el-row>
            </div>
            <div class="center"
                 v-else>
              <div class="value">
                <span class="num">NC</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade">未知</div>
              </el-row>
            </div>
            <!-- <div class="center">
              <div class="value">
                <span class="num">0</span>
                <span class="unit">°C</span>
              </div>
              <div class="outdoor">室外</div>
            </div> -->
          </div>
        </el-col>
        <el-col :span="12">
          <div class="item item3">
            <div class="img">
              <img src="@/assets/images/warnView/device/hum.png" />
            </div>
            <div class="center"
                 v-if="hum">
              <div class="value">
                <span class="num">{{Number(hum.val)?hum.val.toFixed(0):0}}</span>
                <span class="unit">%</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade"
                     :class="hum.evaluate.healthLevelShow|humLevelFil">{{hum.evaluate.healthLevelShow}}</div>
              </el-row>
            </div>
            <div class="center"
                 v-else>
              <div class="value">
                <span class="num">NC</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade">未知</div>
              </el-row>
            </div>
            <!-- <div class="center">
              <div class="value">
                <span class="num">0</span>
                <span class="unit">°C</span>
              </div>
              <div class="outdoor">室外</div>
            </div> -->
          </div>
        </el-col>
        <el-col :span="12">
          <div class="item item2">
            <div class="img">
              <img src="@/assets/images/warnView/device/co2.png" />
            </div>
            <div class="center"
                 v-if="co2">
              <div class="value">
                <span class="num">{{Number(co2.val)?co2.val.toFixed(0):0}}</span>
                <span class="unit">ppm</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade"
                     :class="co2.evaluate.level|co2LevelFil">{{co2.evaluate.healthLevelShow}}</div>
              </el-row>
            </div>
            <div class="center"
                 v-else>
              <div class="value">
                <span class="num">NC</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade">未知</div>
              </el-row>
            </div>
            <!-- <div class="center">
              <div class="value">
                <span class="num">0</span>
                <span class="unit">°C</span>
              </div>
              <div class="outdoor">室外</div>
            </div> -->
          </div>
        </el-col>
        <el-col :span="12">
          <div class="item item1">
            <div class="img">
              <img src="@/assets/images/warnView/device/pm25.png" />
            </div>
            <div class="center"
                 v-if="pm25">
              <div class="value">
                <span class="num">{{Number(pm25.val)?pm25.val.toFixed(0):0}}</span>
                <span class="unit">ug/m³</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade"
                     :class="pm25.evaluate.level|pm25LevelFil">{{pm25.evaluate.healthLevelShow}}</div>
              </el-row>
            </div>
            <div class="center"
                 v-else>
              <div class="value">
                <span class="num">NC</span>
              </div>
              <el-row type="flex"
                      justify="start">
                <div class="indoor">室内</div>
                <div class="grade">未知</div>
              </el-row>
            </div>
            <!-- <div class="center">
              <div class="value">
                <span class="num">0</span>
                <span class="unit">°C</span>
              </div>
              <div class="outdoor">室外</div>
            </div> -->
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import { getAllDeviceDataRealtime } from "@/api/platformManage";
export default {
  name: "overView",
  props: {
    deviceId: {
      type: String,
      default: ""
    },
    deviceName: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      temp: {
        val: 0,
        evaluate:{
          healthLevelShow:0
        }
      },
      hum: {
        val: 0,
        evaluate:{
          healthLevelShow:0
        }
      },
      co2: {
        val: 0,
        evaluate:{
          healthLevelShow:0
        }
      },
      pm25: {
        val: 0,
        evaluate:{
          healthLevelShow:0
        }
      }
    };
  },
  filters: {
    tempLevelFil(level) {
      switch (level) {
        case "适宜":
          return "level-a";
        case "偏冷":
          return "level-c";
        case "偏热":
          return "level-d";
        default:
          return "";
      }
    },
    humLevelFil(level) {
      switch (level) {
        case "适宜":
          return "level-a";
        case "微湿":
          return "level-c";
        case "高湿":
          return "level-yellow";
        case "干燥":
          return "level-d";
        default:
          return "";
      }
    },
    co2LevelFil(level) {
      switch (level) {
        case "LEVEL_A":
          return "level-a";
        case "LEVEL_B":
          return "level-b";
        case "LEVEL_C":
          return "level-c";
        case "LEVEL_D":
          return "level-yellow";
        case "LEVEL_E":
          return "level-e";
        case "LEVEL_F":
          return "level-f";
        default:
          return "";
      }
    },
    pm25LevelFil(level) {
      switch (level) {
        case "LEVEL_A":
          return "level-a";
        case "LEVEL_B":
          return "level-b";
        case "LEVEL_C":
          return "level-yellow";
        case "LEVEL_D":
          return "level-d";
        case "LEVEL_E":
          return "level-e";
        case "LEVEL_F":
          return "level-f";
        default:
          return "";
      }
    }
  },
  watch: {
    deviceId(newVal) {
      this.getAllDeviceDataRealtimeFun(newVal);
    }
  },
  mounted() {
    // this.getAllDeviceDataRealtimeFun(this.deviceId);
  },
  methods: {
    getAllDeviceDataRealtimeFun(deviceId) {
      getAllDeviceDataRealtime(this.deviceId).then(res => {
        var data = res.value;
        if (JSON.stringify(data) == "{}") {
          this.temp = null;
          this.hum = null;
          this.co2 = null;
          this.pm25 = null;
        } else {
          this.temp = data.TEMPERATURE;
          this.hum = data.HUMIDITY;
          this.co2 = data.CO2;
          this.pm25 = data.PM25;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.all-data {
  width: 100%;
  background-color: #fff;
  // height: 312px;
  border-radius: 12px;
  padding: 10px 30px;
  .title {
    font-size: 16px;
    font-weight: bold;
    line-height: 21px;
    color: #0a0a0a;
  }
  .item {
    height: 105px;
    align-items: center;
    display: flex;
    justify-content: left;
    .img {
      display: inline-block;
      margin-right: 10px;
      width: 95px;
    }
    .center {
      margin-top: 13px;
      display: inline-block;
      color: #434343;
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: left;
      font-size: 14px;
      .indoor {
        color: #000;
        width: 60px;
      }
      .num {
        font-size: 30px;
      }
      .unit {
        font-size: 14px;
        line-height: 30px;
      }
      .name {
        color: #9f9f9f;
        font-size: 14px;
      }
      .value {
        width: 100%;
        line-height: 19px;
      }
      .grade {
        width: 100%;
        font-size: 14px;
        font-weight: 400;
      }
    }
  }
  // .item1 {
  //   border-right: solid 0.5px #ececec;
  //   border-bottom: solid 0.5px #ececec;
  // }
  // .item2 {
  //   border-left: solid 0.5px #ececec;
  //   border-bottom: solid 0.5px #ececec;
  // }
  // .item3 {
  //   border-right: solid 0.5px #ececec;
  //   border-top: solid 0.5px #ececec;
  // }
  // .item4 {
  //   border-left: solid 0.5px #ececec;
  //   border-top: solid 0.5px #ececec;
  // }
  .level-a {
    color: #0fc821;
  }
  .level-b {
    color: #0681ed;
  }
  .level-c {
    color: #5bb2ff;
  }
  .level-d {
    color: #ff512d;
  }
  .level-e {
    color: #ff0033;
  }
  .level-f {
    color: #ad0808;
  }
  .level-yellow {
    color: #ffc72d;
  }
}
</style>
